#!/usr/bin/env python3.2
"""WikiBase using PyDbLite with the native Base backend
"""
import os
wikibase_pydblite = Import(os.path.dirname(THIS.app.wikibase_module)+'/wikibase_pydblite.py')
Page = wikibase_pydblite.Page
from PyDbLite import PyDbLite

def _log(self, *args):
    import sys
    for arg in args:
        sys.stderr.write('%s\n' % arg)

class WikiBase(wikibase_pydblite.WikiBase):
    def __init__(self, path):
        self.db = PyDbLite.Base(path)
        self.db.create('name','content','admin','nbvisits','created',
            'version','lastmodif',mode="open")
        self.db.create_index('name')
    
def wikibase(path):
    return WikiBase(path)

if __name__ == "__main__":
    db = wikibase('test.pdl')
    page = db.get('NewPage')
    print(bool(page))
    if page:
        # Existing page
        page.content += '\nExtra stuff\n'
    else:
        # a new page
        page.content = 'Some new text\n'
    db.put(page)
    page = db.get('YetYetYetAnotherPage')
    if not page:
        print('page is new')
    page.content += 'Text for yet another page\n'
    db.put(page)
    print(db.get('NewPage'))
    print(db.get('YetAnotherPage'))
    print()
    for page in db.iter_pages(limit=3):
        print(page)

